#include "graphic_2d_renderer.h"
/*--------------------------------------------------------------------------------*/
#include <GL/gl.h>
#include "graphic_2d_renderer.h"
#include "table.h"
#include "array.h"
#include "graphic_vertex_buffer.h"
#include "graphic_texture.h"
#include "timer.h"
#include "primitives.h"
/*--------------------------------------------------------------------------------*/
IMPLEMENT_SINGLETON( GRAPHIC_2D_RENDERER );
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::SetDrawColor( const COLOR & color )
{
    glColor4f( color.Red, color.Green, color.Blue, color.Alpha );
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::DrawVector2( const MATH_VECTOR_2 & vector )
{
    glBegin( GL_LINES );
    {
        glVertex2f( 0, 0 );
        glVertex2f( vector.X, vector.Y );
    }
    glEnd();
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::DrawRectangle( const MATH_RECTANGLE & rectangle )
{
    glBegin( GL_LINE_LOOP );
    {
        OPENGL_Vertex( rectangle.TopLeftPoint );
        OPENGL_Vertex2f( rectangle.TopLeftPoint.X, rectangle.BottomRightPoint.Y );
        OPENGL_Vertex( rectangle.BottomRightPoint );
        OPENGL_Vertex2f( rectangle.BottomRightPoint.X, rectangle.TopLeftPoint.Y );
    }
    glEnd();
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::AddObject( const GRAPHIC_2D_OBJECT::REF & object )
{
    ObjectTable.Add( object );
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::UpdateObjects( const TIMER & time_step )
{
    INDEX
		index;

    for_each_table_index( index, ObjectTable )
    {
    	ObjectTable[ index ]->Update( time_step );
    }
}
/*--------------------------------------------------------------------------------*/
VOID GRAPHIC_2D_RENDERER::RenderObjects()
{
    INDEX
		index;

    for_each_table_index( index, ObjectTable )
    {
    	ObjectTable[ index ]->Render();
    }
}
/*--------------------------------------------------------------------------------*/

